package com.dly.blog.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dly.blog.controller.BaseController;
import lombok.AllArgsConstructor;
import com.dly.blog.domain.vo.topic.TopicVO;
import com.dly.blog.domain.ro.topic.TopicPageRO;
import com.dly.blog.domain.ro.topic.TopicAddRO;
import com.dly.blog.domain.ro.topic.TopicEditRO;
import com.dly.blog.service.TopicService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.dly.blog.domain.vo.PageVO;
import com.dly.blog.msg.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
 * <p>
 * 主题 前端控制器
 * </p>
 *
 * @author DLY
 * @since 2024-01-24 09:53:18
 */
@Tag(name = "主题相关")
@AllArgsConstructor
@RestController
@RequestMapping("/content/topic")
public class TopicController extends BaseController {

    private final TopicService topicService;

    @PostMapping(value = "/page")
    @Operation(summary = "分页获取主题信息")
    public ResponseEntity<R<PageVO<TopicVO>>> getTopicPage(@RequestBody TopicPageRO topicPageRO){
        return operate(()-> this.successDate(topicService.getTopicPage(topicPageRO)));
    }

    @PostMapping(value = "/add")
    @Operation(summary = "添加主题信息")
    public ResponseEntity<R<Void>> addTopic(@RequestBody TopicAddRO topicAddRO){
        topicService.addTopic(topicAddRO);
        return operate(this::success);
    }

    @PostMapping(value = "/edit")
    @Operation(summary = "修改主题信息")
    public ResponseEntity<R<Void>> editTopic(@RequestBody TopicEditRO topicEditRO){
        topicService.editTopic(topicEditRO);
        return operate(this::success);
    }

    @PostMapping(value = "/get/{id}")
    @Operation(summary = "获取主题信息")
    public ResponseEntity<R<TopicVO>> getTopic(@PathVariable(value = "id") String id){
        return operate(()-> this.successDate(topicService.getTopic(id)));
    }

    @PostMapping(value = "/remove/{ids}")
    @Operation(summary = "删除主题信息")
    public ResponseEntity<R<Void>> removeTopic(@PathVariable(value = "ids") String[] ids){
        topicService.removeTopic(ids);
        return operate(this::success);
    }

}
